Ansible-playbook 安装windows环境 JDK


baiyongjie

关注
2018.10.30 16:48:23
字数 77
阅读 771
使用Ansible在windows环境下安装Java

使用到的模块

win_copy: 复制软件安装程序到windows主机
win_package: 安装软件包
win_path: 添加环境变量
win_reboot: 重启windows服务器
win_shell: 检查java安装情况
debug: 输出检查结果
编写playbook


[root@squid win_java_install]# cat win_install_java.yaml 
---
- hosts: windows
  tasks:
  - name: copy jdk software to remote host
    win_copy: src=jdk-7u2-windows-x64.exe  dest=c:\\tools\\

  - name: install java
    win_package:
      path: c:\\tools\\jdk-7u2-windows-x64.exe
      product_id: jdk-7u2
      arguments:
        - /s
        - /quiet
      state: present

  - name: Add JAVA_HOME Env
    win_path:
      name: JAVA_HOME
      elements: C:\Program Files\Java\jdk1.7.0_02
      scope: machine
      state: present

  - name: Add JAVA_BIN Env
    win_path:
      name: PATH
      elements: C:\Program Files\Java\jdk1.7.0_02\bin
      scope: machine
      state: present

  - name: Reboot Windows Server
    win_reboot:
      msg: "Restart the server 3 seconds later"
      post_reboot_delay: 3
      test_command: whoami

  - name: check jdk shell
    win_shell: "java -version"
    args:
      executable: cmd
    register: java_version

  - debug: msg="{{java_version.stderr_lines}}"